www.gusucode.com > VC++ outlookbar控件CXTOutBarCtrl源码程序 > VC++ outlookbar控件CXTOutBarCtrl源码程序/code/MainFrm.cpp
// MainFrm.cpp : implementation of the CMainFrame class // Download by http://www.NewXing.com #include "stdafx.h" #include "Demo.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_WM_DESTROY() //}}AFX_MSG_MAP ON_MESSAGE(XTWM_OUTBAR_NOTIFY, OnOutbarNotify) END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } LRESULT CMainFrame::OnOutbarNotify(WPARAM wParam, LPARAM lParam) { int nBarAction = (int)wParam; // Cast the lParam to a XT_OUTBAR_INFO* struct pointer. XT_OUTBAR_INFO* pOBInfo = (XT_OUTBAR_INFO*)lParam; ASSERT(pOBInfo); switch (nBarAction) { case OBN_XT_ITEMCLICK: {CString strMsg=pOBInfo->lpszText; AfxMessageBox(strMsg); TRACE2( "Item selected: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); } break; case OBN_XT_FOLDERCHANGE: TRACE2( "Folder selected: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); break; case OBN_XT_ONLABELENDEDIT: TRACE2( "Item edited: %d, New name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); break; case OBN_XT_ONGROUPENDEDIT: TRACE2( "Folder edited: %d, New name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); break; case OBN_XT_DRAGITEM: TRACE3( "Dragging From: %d, To: %d, Name: %s.\n", pOBInfo->nDragFrom, pOBInfo->nDragTo, pOBInfo->lpszText); break; case OBN_XT_ITEMHOVER: TRACE2( "Hovering Item: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); break; case OBN_XT_DELETEITEM: if (!m_bDestroy && AfxMessageBox(_T("Are you sure you want to remove this folder shortcut?"), MB_ICONWARNING|MB_YESNO) == IDNO) { // The user selected No, return FALSE to abort the action. return FALSE; } TRACE2( "Item deleted: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); break; case OBN_XT_DELETEFOLDER: if (!m_bDestroy && AfxMessageBox(_T("Are you sure you want to remove the specified folder?"), MB_ICONWARNING|MB_YESNO) == IDNO) { // The user selected No, return FALSE to abort the action. return FALSE; } TRACE2( "Folder deleted: %d, Name: %s.\n", pOBInfo->nIndex, pOBInfo->lpszText); break; } return TRUE; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { // create splitter window if (!m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE; // Here we create the outbar control using the splitter as its parent // and setting its id to the first pane. if (!m_wndOutlookBar.Create(WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN, CRect(0,0,0,0), &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0), OBS_XT_DEFAULT)) { TRACE0("Failed to create outlook bar."); return FALSE; } if (!m_wndSplitter.CreateView(0, 1, pContext->m_pNewViewClass, CSize(100, 100), pContext)) { m_wndSplitter.DestroyWindow(); return FALSE; } // Set the background and text color of the outlook bar. m_wndOutlookBar.SetBackColor(RGB(0x3a,0x6e,0xa5)); m_wndOutlookBar.SetTextColor(RGB(0xff,0xff,0xff)); // Set the default sizes for the splitter panes. CRect r; GetClientRect(&r); m_wndSplitter.SetColumnInfo( 0, r.Width()/4, 0 ); m_wndSplitter.RecalcLayout(); // Add items to the outlook bar. InitializeOutlookBar(); return TRUE; } static UINT nIcons[] = { IDI_ICON1, IDI_ICON3, IDI_ICON4, IDI_ICON7, IDI_ICON8, IDI_ICON2, IDI_ICON11, IDI_ICON6, IDI_ICON9, IDI_ICON10, IDI_ICON5 }; void CMainFrame::InitializeOutlookBar() { // Create the image lists used by the outlook bar. m_ImageSmall.Create (16, 16, ILC_COLOR16|ILC_MASK, 2, 1); m_ImageLarge.Create (32, 32, ILC_COLOR16|ILC_MASK, 2, 1); // initiailize the image lists. for (int i = 0; i < 11; ++i) { HICON hIcon = AfxGetApp()->LoadIcon(nIcons[i]); ASSERT(hIcon); m_ImageSmall.Add(hIcon); m_ImageLarge.Add(hIcon); } int iFolder; // index of the added folder // set the image lists for the outlook bar. m_wndOutlookBar.SetImageList(&m_ImageLarge, OBS_XT_LARGEICON); m_wndOutlookBar.SetImageList(&m_ImageSmall, OBS_XT_SMALLICON); // Add the first folder to the outlook bar. iFolder = m_wndOutlookBar.AddFolder(_T("Shortcuts 1"), 0); // Add items to the folder, syntax is folder, index, text, image, and item data. m_wndOutlookBar.InsertItem(iFolder, 1, _T("Item 1"), 0, NULL); m_wndOutlookBar.InsertItem(iFolder, 2, _T("Item 2"), 1, NULL); m_wndOutlookBar.InsertItem(iFolder, 3, _T("Item 3"), 2, NULL); m_wndOutlookBar.InsertItem(iFolder, 4, _T("Item 4"), 3, NULL); m_wndOutlookBar.InsertItem(iFolder, 5, _T("Item 5"), 4, NULL); m_wndOutlookBar.InsertItem(iFolder, 6, _T("Item 6"), 5, NULL); // Add the second folder to the outlook bar. iFolder = m_wndOutlookBar.AddFolder(_T("Shortcuts 2"), 1); // Add items to the folder, syntax is folder, index, text, image, and item data. m_wndOutlookBar.InsertItem(iFolder, 1, _T("Item 1"), 0, NULL); m_wndOutlookBar.InsertItem(iFolder, 2, _T("Item 2"), 1, NULL); // Add the tree control to the outlook bar. //xu iFolder = m_wndOutlookBar.AddFolderBar(_T("Tree Control"), &m_wndTreeCtrl ); // Set the default font used by the outlook bar. //xu m_wndOutlookBar.SetFontX(&xtAfxData.font); // We want to receive notification messages. m_wndOutlookBar.SetOwner(this); // Select the first folder in the bar. m_wndOutlookBar.SetSelFolder(iFolder); // Sizing for splitter CRect r; GetClientRect(&r); m_wndSplitter.SetColumnInfo( 0, r.Width()/7, 0 ); m_wndSplitter.SetColumnInfo( 1, r.Width()/5, 0 ); // m_wndSplitter1.SetSplitterStyle(XT_SPLIT_NOFULLDRAG); } void CMainFrame::OnDestroy() { m_bDestroy = true; CFrameWnd::OnDestroy(); }